package spring.cloud.tasks.executor.name_space.executor.tasks_runtime_info.task_item_assign;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.recipes.cache.NodeCache;
import org.apache.curator.framework.recipes.cache.NodeCacheListener;

@Slf4j
@Setter
@Getter
public class TaskItemAssignListener implements NodeCacheListener {
    public NodeCache nodeCache;
    public TaskIdToTaskInstanceIdToTaskItemIndexListMapMap taskIdToTaskInstanceIdToTaskItemIndexListMapMap;

    public TaskItemAssignListener(NodeCache nodeCache, TaskIdToTaskInstanceIdToTaskItemIndexListMapMap taskIdToTaskInstanceIdToItemIndexListMapMap) {
        this.nodeCache = nodeCache;
        this.taskIdToTaskInstanceIdToTaskItemIndexListMapMap = taskIdToTaskInstanceIdToItemIndexListMapMap;
    }

    @Override
    public void nodeChanged() throws Exception {
        String value = null;
        if (null != nodeCache.getCurrentData()) {
            value = new String(nodeCache.getCurrentData().getData());
        }
        log.info("接收到NodeCacheListener事件，节点：{}，值：{}", nodeCache.getCurrentData().getPath(), value);
        //如果表示更新
        taskIdToTaskInstanceIdToTaskItemIndexListMapMap.get();
    }
}
